package com.woniu108.person.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu108.carService.commos.dto.StoreAdminSimpleDto;
import com.woniu108.carService.commos.exception.WoniuException;
import com.woniu108.person.mapper.StoreAdminMapper;
import com.woniu108.person.model.StoreAdmin;
import com.woniu108.person.param.StoreAdminLoginParam;
import com.woniu108.person.service.StoreAdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yanxi
 * @since 2024-05-23
 */
@Service
public class StoreAdminServiceImpl extends ServiceImpl<StoreAdminMapper, StoreAdmin> implements StoreAdminService {


    @Resource
    private StoreAdminMapper storeAdminMapper;

    @Override
    public StoreAdminSimpleDto storeAdminLogin(StoreAdminLoginParam param) {
        //根据管理员账号名称判断账号
        QueryWrapper<StoreAdmin> wrapper = new QueryWrapper<>();
        wrapper.eq("store_admin_name",param.getStoreAdminName());
        StoreAdmin storeAdminInfo = storeAdminMapper.selectOne(wrapper);
        if(ObjectUtil.isEmpty(storeAdminInfo)) throw new WoniuException("用户名不存在",10001);
        if(!storeAdminInfo.getStoreAdminPass().equals(param.getStoreAdminPass())) throw new WoniuException("密码有误",10001);
        //获取storeAdminInfo转storeAdminSimpleDto返回
        StoreAdminSimpleDto dto = BeanUtil.toBean(storeAdminInfo, StoreAdminSimpleDto.class);
        return dto;
    }
}
